home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00a.txt / 000014_icon-group-sender _Thu Jan 20 17:06:44 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id RAA23952
  4.     for icon-group-addresses; Thu, 20 Jan 2000 17:06:34 -0700 (MST)
  5. Message-Id: <200001210006.RAA23952@baskerville.CS.Arizona.EDU>
  6. X-Authentication-Warning: agate.berkeley.edu: news set sender to <news> using -f
  7. From: espie@liafa.jussieu.fr (Marc Espie)
  8. X-Newsgroups: comp.lang.icon
  9. Subject: Re: Question
  10. Date: 20 Jan 2000 20:22:46 GMT
  11. X-Trace: vishnu.jussieu.fr 948399766 688 132.227.81.128 (20 Jan 2000 20:22:46 GMT)
  12. X-Complaints-To: Newsmaster@jussieu.fr.
  13. X-Newsreader: trn 4.0-test70 (17 January 1999)
  14. To: icon-group@optima.CS.Arizona.EDU
  15. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  16. Status: RO
  17.  
  18. In article <200001201933.MAA09251@baskerville.CS.Arizona.EDU>,
  19. Steve Graham <Steve_Graham@labcorp.com> wrote:
  20. >I need a program which generates all combinations (or permutations?) of
  21. >12345, i.e. 12345, 12354, 12435, etc  I have a hunch that Icon has built
  22. >in facilities to accomplish this, but I haven't figured out what they
  23. >are.  Any suggestions?
  24.  
  25. If you don't need to build them in lexicographic order, this is easily
  26. achieved with a recursive generator.
  27.  
  28. Try this:
  29.  
  30. procedure permute(l, i)
  31.    if i >= *l then
  32.       return l
  33.    else
  34.       suspend l[i to *l] <-> l[i] & permute(l, i+1)
  35. end
  36.  
  37. procedure write_list(l)
  38.    every writes(!l, " ")
  39.    write()
  40. end
  41.  
  42. procedure main()
  43.    every write_list(permute(["a", "b", "c"], 1))
  44. end
  45.  
  46.  
  47. -- 
  48.     Marc Espie        
  49. |anime, sf, juggling, unicycle, acrobatics, comics...
  50. |AmigaOS, OpenBSD, C++, perl, Icon, PostScript...
  51. | `real programmers don't die, they just get out of beta'
  52.